package com.ext.aic.handler;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import java.io.Serializable;

public class BundleHandler {

    public Bundle initBundle(Activity activity) {
        Intent intent = activity.getIntent();
        if (intent == null) {
            return null;
        }
        return intent.getExtras();
    }

    public Bundle initBundle(Fragment fragment) {
        return fragment.getArguments();
    }

    public String getBundleString(Bundle bundle, String key) {
        return bundle.getString(key);
    }

    public int getBundleInt(Bundle bundle, String key) {
        return bundle.getInt(key);
    }

    public long getBundleLong(Bundle bundle, String key) {
        return bundle.getLong(key);
    }

    public boolean getBundleBoolean(Bundle bundle, String key) {
        return bundle.getBoolean(key);
    }

    public <T extends Serializable> T getSerializable(Bundle bundle, String key, Class<T> clazz) {
        return (T) bundle.getSerializable(key);
    }
}
